export const selectionSort = (arr) => {
    for (let i = 0; i < arr.length; i++) {

        for (let j = i; j < arr.length; j++) {
            if (arr[j] < arr[i]) {
                const tmp = arr[i]
                arr[i] = arr[j]
                arr[j] = tmp
            }
        }

    }
    return arr
}

export const selectionSort2 = (arr) => {
    for (let i = 0; i < arr.length; i++) {
        let minIndex = i

        for (let j = i; j < arr.length; j++) {
            if (arr[j] < arr[minIndex]) {
                minIndex = j
            }
        }

        swap(arr, i, minIndex)
    }

    return arr
}

const swap = (arr, i, j) => {
    const tmp = arr[i]

    arr[i] = arr[j]
    arr[j] = tmp
}
